package edos.prm.metrics;

import java.util.HashSet;
import java.util.Set;

import edos.prm.activity.Activity;
import edos.prm.project.Project;
import edos.prm.project.Topic;

/**
 * A {@code MetricViewpoint} describes the purpose and main properties of a
 * metric.
 */
public class MetricViewpoint {

	private Project project;
	private HashSet<Topic> topics;
	private HashSet<Activity> activities;
	private String description;
	
	/**
	 * Create a MetricViewpoint for a project, set of activities and topics.
	 * 
	 * @param project the project the metric is designed for.
	 * @param projectTopics the set of topics covered in this metric.
	 * @param activities the activities dealt with by this metric.
	 * @param description a textual explanation of the metric.
	 */
	public MetricViewpoint(Project project, Set<Topic> projectTopics,
			Set<Activity> activities, String description) {
		this.project = project;
		this.topics = new HashSet<Topic>();
		this.topics.addAll(projectTopics);
		this.activities = new HashSet<Activity>();
		this.activities.addAll(activities);
		this.description = description;
	}
	
	/**
	 * Return the project associated with this metric.
	 * 
	 * @return the metric's project.
	 */
	public Project getProject() {
		return project;
	}
	
	/**
	 * Return the activities covered by this metric.
	 * 
	 * @return the metric's activities in a Set.
	 */
	public Set<Topic> getTopics() {
		HashSet<Topic> result = new HashSet<Topic>();
		result.addAll(topics);
		return result;
	}
	
	/**
	 * Return the textual description of this metric.
	 * 
	 * @return a String representing the description of the metric.
	 */
	public String getDescription() {
		return this.description;
	}
	
	/**
	 * Return the activities that the metric covers.
	 * 
	 * @return a set of the activities covered by this metric.
	 */
	public Set<Activity> getActivities() {
		HashSet<Activity> result = new HashSet<Activity>();
		result.addAll(this.activities);
		return result;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((activities == null) ? 0 : activities.hashCode());
		result = prime * result + ((project == null) ? 0 : project.hashCode());
		result = prime * result + ((topics == null) ? 0 : topics.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MetricViewpoint other = (MetricViewpoint) obj;
		if (activities == null) {
			if (other.activities != null)
				return false;
		} else if (!activities.equals(other.activities))
			return false;
		if (project == null) {
			if (other.project != null)
				return false;
		} else if (!project.equals(other.project))
			return false;
		if (topics == null) {
			if (other.topics != null)
				return false;
		} else if (!topics.equals(other.topics))
			return false;
		return true;
	}
}
